<?php
require_once("database.php");
class xl_bo_dem extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from bo_dem limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong_hom_nay()
	{
		$from = date('Y-m-d 0:0:0');
		$to = date('Y-m-d 23:59:59');
		$sql = "select count(*) from bo_dem where '$from' <= thoi_gian and thoi_gian <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong_hom_qua()
	{
		$from = date('Y-m-d 0:0:0',  strtotime('-1 days') );
		$to = date('Y-m-d 23:59:59' ,  strtotime('-1 days'));
		$sql = "select count(*) from bo_dem where  '$from' <= thoi_gian and thoi_gian <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong_tuan_nay()
	{
		$x = date('w');
		
		$from = date('Y-m-d 0:0:0',  strtotime("-$x days"));
		$to = date('Y-m-d 23:59:59');
		$sql = "select count(*) from bo_dem where  '$from' <= thoi_gian and thoi_gian <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong_thang_nay()
	{
		$from = date('Y-m-1 0:0:0');
		$to = date('Y-m-d 23:59:59');
		$sql = "select count(*) from bo_dem where  '$from' <= thoi_gian and thoi_gian <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	
	function so_luong_theo_ngay($ngay)
	{
		$from = date("$ngay 0:0:0");
		$to = date("$ngay 23:59:59");
		$sql = "select count(*) from bo_dem where  '$from' <= thoi_gian and thoi_gian <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong()
	{
		$sql = "select count(*) from bo_dem";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from bo_dem where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from bo_dem where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function them($dia_chi_ip, $trinh_duyet, $thoi_gian, $url)
	{
		$dia_chi_ip = stripslashes($dia_chi_ip);
		$dia_chi_ip = addslashes($dia_chi_ip);
		$trinh_duyet = stripslashes($trinh_duyet);
		$trinh_duyet = addslashes($trinh_duyet);
		$url = stripslashes($url);
		$url = addslashes($url);

		$sql = "INSERT INTO bo_dem(dia_chi_ip,trinh_duyet,thoi_gian,url) VALUES ('$dia_chi_ip','$trinh_duyet','$thoi_gian','$url')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $dia_chi_ip, $trinh_duyet, $thoi_gian, $url)
	{
		$ma = intval($ma);
		$dia_chi_ip = stripslashes($dia_chi_ip);
		$dia_chi_ip = addslashes($dia_chi_ip);
		$trinh_duyet = stripslashes($trinh_duyet);
		$trinh_duyet = addslashes($trinh_duyet);
		$url = stripslashes($url);
		$url = addslashes($url);

		$sql ="UPDATE bo_dem SET dia_chi_ip= '$dia_chi_ip', trinh_duyet= '$trinh_duyet', thoi_gian= '$thoi_gian', url= '$url' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from bo_dem where	$dia_chi_ip like %tu_khoa% or 	$trinh_duyet like %tu_khoa% or 	$url like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>